using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Text;

namespace System.Text
{
	/// <summary>
	/// The EnhancedStringBuilder class
	/// </summary>
	/// <created author="laurentiu.macovei" date="Wed, 29 Nov 2006 11:19:30 GMT"/>
	[DebuggerDisplay("{Text}")]
	public class EnhancedStringBuilder
	{

		#region Fields

		System.Text.StringBuilder sb;
		private object _Tag;

		#endregion Fields


		#region Constructors

		/// <summary>Creates a new instance of EnhancedStringBuilder</summary>
		/// <created author="laurentiu.macovei" date="Wed, 29 Nov 2006 11:19:30 GMT"/>
		public EnhancedStringBuilder()
		{
			sb = new System.Text.StringBuilder();
		}

		/// <summary>Creates a new instance of EnhancedStringBuilder</summary>
		/// <param name="capacity"></param>
		/// <created author="laurentiu.macovei" date="Wed, 29 Nov 2006 11:19:30 GMT"/>
		public EnhancedStringBuilder(int capacity)
		{
			sb = new System.Text.StringBuilder(capacity);
		}

		/// <summary>Creates a new instance of EnhancedStringBuilder</summary>
		/// <param name="value"></param>
		/// <created author="laurentiu.macovei" date="Wed, 29 Nov 2006 11:19:30 GMT"/>
		public EnhancedStringBuilder(string value)
		{
			sb = new System.Text.StringBuilder(value);
		}

		/// <summary>Creates a new instance of EnhancedStringBuilder</summary>
		/// <param name="capacity"></param>
		/// <param name="maxCapacity"></param>
		/// <created author="laurentiu.macovei" date="Wed, 29 Nov 2006 11:19:30 GMT"/>
		public EnhancedStringBuilder(int capacity, int maxCapacity)
		{
			sb = new System.Text.StringBuilder(capacity, maxCapacity);
		}

		/// <summary>Creates a new instance of EnhancedStringBuilder</summary>
		/// <param name="value"></param>
		/// <param name="capacity"></param>
		/// <created author="laurentiu.macovei" date="Wed, 29 Nov 2006 11:19:30 GMT"/>
		public EnhancedStringBuilder(string value, int capacity)
		{
			sb = new System.Text.StringBuilder(value, capacity);
		}

		/// <summary>Creates a new instance of EnhancedStringBuilder</summary>
		/// <param name="value"></param>
		/// <param name="startIndex"></param>
		/// <param name="length"></param>
		/// <param name="capacity"></param>
		/// <created author="laurentiu.macovei" date="Wed, 29 Nov 2006 11:19:30 GMT"/>
		public EnhancedStringBuilder(string value, int startIndex, int length, int capacity)
		{
			sb = new System.Text.StringBuilder(value, startIndex, length, capacity);
		}


		#endregion Constructors


		#region Properties
		/// <summary>Returns the EnhancedStringBuilder.ToString()</summary>
		/// <created author="laurentiu.macovei" date="Sat, 18 Oct 2008 17:01:20 GMT"/>
		public string Text
		{
			get { return sb.ToString(); }
		}

		/// <summary>Gets the underline StringBuilder</summary>
		/// <created author="laurentiu.macovei" date="Thu, 18 Jan 2007 14:23:36 GMT"/>
		public System.Text.StringBuilder StringBuilder
		{
			get { return sb; }
		}

		/// <summary>Gets or sets the Tag</summary>
		/// <created author="laurentiu.macovei" date="Wed, 29 Nov 2006 11:19:30 GMT"/>
		public object Tag
		{
			get { return _Tag; }
			set { _Tag = value; }
		}

		/// <summary>Gets or sets the Capacity</summary>
		/// <created author="laurentiu.macovei" date="Wed, 29 Nov 2006 11:19:30 GMT"/>
		public int Capacity
		{
			get { return sb.Capacity; }
			set { sb.Capacity = value; }
		}

		/// <summary>Gets or sets the this</summary>
		/// <created author="laurentiu.macovei" date="Wed, 29 Nov 2006 11:19:30 GMT"/>
		public char this[int index]
		{
			get { return sb[index]; }
			set { sb[index] = value; }
		}

		/// <summary>Gets or sets the Length</summary>
		/// <created author="laurentiu.macovei" date="Wed, 29 Nov 2006 11:19:30 GMT"/>
		public int Length
		{
			get { return sb.Length; }
			set { sb.Length = value; }
		}

		/// <summary>Gets the MaxCapacity</summary>
		/// <created author="laurentiu.macovei" date="Wed, 29 Nov 2006 11:19:30 GMT"/>
		public int MaxCapacity
		{
			get { return sb.MaxCapacity; }
		}


		#endregion Properties


		#region Override Methods

		/// <summary>
		/// </summary>
		/// <returns></returns>
		/// <created author="laurentiu.macovei" date="Wed, 29 Nov 2006 11:19:31 GMT"/>
		public override string ToString()
		{
			return sb.ToString();
		}


		#endregion Override Methods


		#region Business Methods

		/// <summary>
		/// </summary>
		/// <param name="sb"></param>
		/// <returns></returns>
		/// <created author="laurentiu.macovei" date="Mon, 29 Jan 2007 20:15:00 GMT"/>
		public static implicit operator string(EnhancedStringBuilder sb)
		{
			return sb == null ? null : sb.ToString();
		}

		/// <summary>
		/// </summary>
		/// <param name="value"></param>
		/// <returns></returns>
		/// <created author="laurentiu.macovei" date="Mon, 29 Jan 2007 23:45:10 GMT"/>
		public static implicit operator EnhancedStringBuilder(string value)
		{
			if (value == null)
				return null;
			EnhancedStringBuilder sb = new EnhancedStringBuilder();
			sb.Append(value);
			return sb;
		}

		/// <summary>
		/// </summary>
		/// <param name="sb"></param>
		/// <param name="value"></param>
		/// <returns></returns>
		/// <created author="laurentiu.macovei" date="Mon, 29 Jan 2007 20:15:00 GMT"/>
		public static EnhancedStringBuilder operator +(EnhancedStringBuilder sb, string value)
		{
			if (sb == null)
				sb = new EnhancedStringBuilder();
			sb.Append(value);
			return sb;
		}

		/// <summary>
		/// </summary>
		/// <param name="sb"></param>
		/// <param name="value"></param>
		/// <returns></returns>
		/// <created author="laurentiu.macovei" date="Mon, 29 Jan 2007 20:15:40 GMT"/>
		public static EnhancedStringBuilder operator +(EnhancedStringBuilder sb, int value)
		{
			if (sb == null)
				sb = new EnhancedStringBuilder();
			sb.Append(value);
			return sb;
		}

		/// <summary>Gets the underlining string builder</summary>
		/// <param name="sb"></param>
		/// <returns></returns>
		/// <created author="laurentiu.macovei" date="Thu, 18 Jan 2007 14:25:52 GMT"/>
		public static implicit operator System.Text.StringBuilder(EnhancedStringBuilder sb)
		{
			return sb.sb;
		}

		/// <summary>
		/// </summary>
		/// <param name="value"></param>
		/// <returns></returns>
		/// <created author="laurentiu.macovei" date="Wed, 29 Nov 2006 11:19:31 GMT"/>
		public StringBuilder Append(bool value)
		{
			return sb.Append(value);
		}

		/// <summary>
		/// </summary>
		/// <param name="value"></param>
		/// <returns></returns>
		/// <created author="laurentiu.macovei" date="Wed, 29 Nov 2006 11:19:31 GMT"/>
		public StringBuilder Append(byte value)
		{
			return sb.Append(value);
		}

		/// <summary>
		/// </summary>
		/// <param name="value"></param>
		/// <returns></returns>
		/// <created author="laurentiu.macovei" date="Wed, 29 Nov 2006 11:19:31 GMT"/>
		public StringBuilder Append(char value)
		{
			return sb.Append(value);
		}

		/// <summary>
		/// </summary>
		/// <param name="value"></param>
		/// <returns></returns>
		/// <created author="laurentiu.macovei" date="Wed, 29 Nov 2006 11:19:31 GMT"/>
		public StringBuilder Append(decimal value)
		{
			return sb.Append(value);
		}

		/// <summary>
		/// </summary>
		/// <param name="value"></param>
		/// <returns></returns>
		/// <created author="laurentiu.macovei" date="Wed, 29 Nov 2006 11:19:31 GMT"/>
		public StringBuilder Append(double value)
		{
			return sb.Append(value);
		}

		/// <summary>
		/// </summary>
		/// <param name="value"></param>
		/// <returns></returns>
		/// <created author="laurentiu.macovei" date="Wed, 29 Nov 2006 11:19:31 GMT"/>
		public StringBuilder Append(short value)
		{
			return sb.Append(value);
		}

		/// <summary>
		/// </summary>
		/// <param name="value"></param>
		/// <returns></returns>
		/// <created author="laurentiu.macovei" date="Wed, 29 Nov 2006 11:19:31 GMT"/>
		public StringBuilder Append(int value)
		{
			return sb.Append(value);
		}

		/// <summary>
		/// </summary>
		/// <param name="value"></param>
		/// <returns></returns>
		/// <created author="laurentiu.macovei" date="Wed, 29 Nov 2006 11:19:31 GMT"/>
		public StringBuilder Append(long value)
		{
			return sb.Append(value);
		}

		/// <summary>
		/// </summary>
		/// <param name="value"></param>
		/// <returns></returns>
		/// <created author="laurentiu.macovei" date="Wed, 29 Nov 2006 11:19:31 GMT"/>
		public StringBuilder Append(object value)
		{
			return sb.Append(value);
		}

		/// <summary>
		/// </summary>
		/// <param name="value"></param>
		/// <returns></returns>
		/// <created author="laurentiu.macovei" date="Wed, 29 Nov 2006 11:19:31 GMT"/>
		public StringBuilder Append(float value)
		{
			return sb.Append(value);
		}

		/// <summary>
		/// </summary>
		/// <param name="value"></param>
		/// <returns></returns>
		/// <created author="laurentiu.macovei" date="Wed, 29 Nov 2006 11:19:31 GMT"/>
		public StringBuilder Append(string value)
		{
			return sb.Append(value);
		}

		/// <summary>
		/// </summary>
		/// <param name="values"></param>
		/// <returns></returns>
		/// <created author="laurentiu.macovei" date="Wed, 29 Nov 2006 11:19:31 GMT"/>
		public EnhancedStringBuilder Append(params string[] values)
		{
			if (values != null)
				foreach (string value in values)
					if (value != null)
					{
						sb.Append(value);
					}
			return this;
		}
		/// <summary>
		/// </summary>
		/// <param name="values"></param>
		/// <returns></returns>
		/// <created author="laurentiu.macovei" date="Wed, 19 Jan 2011 23:11:48 GMT"/>
		public EnhancedStringBuilder Append(params object[] values)
		{
			if (values != null)
				foreach (string value in values)
					if (value != null)
					{
						sb.Append(value);
					}
			return this;
		}

		/// <summary>
		/// </summary>
		/// <param name="values"></param>
		/// <param name="EnhancedStringBuilder"></param>
		/// <returns></returns>
		/// <created author="laurentiu.macovei" date="Wed, 29 Nov 2006 11:19:31 GMT"/>
		public StringBuilder Append(EnhancedStringBuilder EnhancedStringBuilder, params string[] values)
		{
			sb.Append(EnhancedStringBuilder.sb);
			if (values != null)
				foreach (string value in values)
				{
					sb.Append(value);
				}
			return sb;
		}

		/// <summary>
		/// </summary>
		/// <param name="value"></param>
		/// <returns></returns>
		/// <created author="laurentiu.macovei" date="Wed, 29 Nov 2006 11:19:31 GMT"/>
		public StringBuilder Append(char[] value)
		{
			return sb.Append(value);
		}

		/// <summary>
		/// </summary>
		/// <param name="value"></param>
		/// <param name="repeatCount"></param>
		/// <returns></returns>
		/// <created author="laurentiu.macovei" date="Wed, 29 Nov 2006 11:19:31 GMT"/>
		public StringBuilder Append(char value, int repeatCount)
		{
			return sb.Append(value, repeatCount);
		}

		/// <summary>
		/// </summary>
		/// <param name="value"></param>
		/// <param name="startIndex"></param>
		/// <param name="charCount"></param>
		/// <returns></returns>
		/// <created author="laurentiu.macovei" date="Wed, 29 Nov 2006 11:19:31 GMT"/>
		public StringBuilder Append(char[] value, int startIndex, int charCount)
		{
			return sb.Append(value, startIndex, charCount);
		}

		/// <summary>
		/// </summary>
		/// <param name="value"></param>
		/// <param name="startIndex"></param>
		/// <param name="length"></param>
		/// <returns></returns>
		/// <created author="laurentiu.macovei" date="Wed, 29 Nov 2006 11:19:31 GMT"/>
		public StringBuilder Append(string value, int startIndex, int length)
		{
			return sb.Append(value, startIndex, length);
		}

		/// <summary>
		/// </summary>
		/// <param name="format"></param>
		/// <param name="args"></param>
		/// <returns></returns>
		/// <created author="laurentiu.macovei" date="Wed, 29 Nov 2006 11:19:31 GMT"/>
		public StringBuilder AppendFormat(string format, params object[] args)
		{
			return sb.AppendFormat(format, args);
		}

		/// <summary>
		/// </summary>
		/// <param name="format"></param>
		/// <param name="arg0"></param>
		/// <returns></returns>
		/// <created author="laurentiu.macovei" date="Wed, 29 Nov 2006 11:19:31 GMT"/>
		public StringBuilder AppendFormat(string format, object arg0)
		{
			return sb.AppendFormat(format, arg0);
		}

		/// <summary>
		/// </summary>
		/// <param name="provider"></param>
		/// <param name="format"></param>
		/// <param name="args"></param>
		/// <returns></returns>
		/// <created author="laurentiu.macovei" date="Wed, 29 Nov 2006 11:19:31 GMT"/>
		public StringBuilder AppendFormat(IFormatProvider provider, string format, params object[] args)
		{
			return sb.AppendFormat(provider, format, args);
		}

		/// <summary>
		/// </summary>
		/// <param name="format"></param>
		/// <param name="arg0"></param>
		/// <param name="arg1"></param>
		/// <returns></returns>
		/// <created author="laurentiu.macovei" date="Wed, 29 Nov 2006 11:19:31 GMT"/>
		public StringBuilder AppendFormat(string format, object arg0, object arg1)
		{
			return sb.AppendFormat(format, arg0, arg1);
		}

		/// <summary>
		/// </summary>
		/// <param name="format"></param>
		/// <param name="arg0"></param>
		/// <param name="arg1"></param>
		/// <param name="arg2"></param>
		/// <returns></returns>
		/// <created author="laurentiu.macovei" date="Wed, 29 Nov 2006 11:19:31 GMT"/>
		public StringBuilder AppendFormat(string format, object arg0, object arg1, object arg2)
		{
			return sb.AppendFormat(format, arg0, arg1, arg2);
		}

		/// <summary>
		/// </summary>
		/// <returns></returns>
		/// <created author="laurentiu.macovei" date="Wed, 29 Nov 2006 11:19:31 GMT"/>
		public StringBuilder AppendLine()
		{
			return sb.AppendLine();
		}

		/// <summary>
		/// </summary>
		/// <param name="value"></param>
		/// <returns></returns>
		/// <created author="laurentiu.macovei" date="Wed, 29 Nov 2006 11:19:31 GMT"/>
		public StringBuilder AppendLine(string value)
		{
			return sb.AppendLine(value);
		}

		/// <summary>
		/// </summary>
		/// <param name="sourceIndex"></param>
		/// <param name="destination"></param>
		/// <param name="destinationIndex"></param>
		/// <param name="count"></param>
		/// <created author="laurentiu.macovei" date="Wed, 29 Nov 2006 11:19:31 GMT"/>
		public void CopyTo(int sourceIndex, char[] destination, int destinationIndex, int count)
		{
			sb.CopyTo(sourceIndex, destination, destinationIndex, count);
		}

		/// <summary>
		/// </summary>
		/// <param name="capacity"></param>
		/// <returns></returns>
		/// <created author="laurentiu.macovei" date="Wed, 29 Nov 2006 11:19:31 GMT"/>
		public int EnsureCapacity(int capacity)
		{
			return sb.EnsureCapacity(capacity);
		}

		/// <summary>
		/// </summary>
		/// <param name="sb"></param>
		/// <returns></returns>
		/// <created author="laurentiu.macovei" date="Wed, 29 Nov 2006 11:19:31 GMT"/>
		public bool Equals(StringBuilder sb)
		{
			return sb.Equals(sb);
		}

		/// <summary>
		/// </summary>
		/// <param name="startIndex"></param>
		/// <param name="length"></param>
		/// <returns></returns>
		/// <created author="laurentiu.macovei" date="Wed, 29 Nov 2006 11:19:31 GMT"/>
		public string ToString(int startIndex, int length)
		{
			return sb.ToString(startIndex, length);
		}

		/// <summary>
		/// </summary>
		/// <param name="startIndex"></param>
		/// <param name="length"></param>
		/// <returns></returns>
		/// <created author="laurentiu.macovei" date="Wed, 29 Nov 2006 11:19:31 GMT"/>
		public StringBuilder Remove(int startIndex, int length)
		{
			return sb.Remove(startIndex, length);
		}

		/// <summary>Empties the string builder</summary>
		/// <created author="laurentiu.macovei" date="Sat, 02 Dec 2006 18:04:00 GMT"/>
		public void Clear()
		{
			sb.Remove(0, sb.Length);
		}

		/// <summary>
		/// </summary>
		/// <param name="oldChar"></param>
		/// <param name="newChar"></param>
		/// <returns></returns>
		/// <created author="laurentiu.macovei" date="Wed, 29 Nov 2006 11:19:31 GMT"/>
		public StringBuilder Replace(char oldChar, char newChar)
		{
			return sb.Replace(oldChar, newChar);
		}

		/// <summary>
		/// </summary>
		/// <param name="oldValue"></param>
		/// <param name="newValue"></param>
		/// <returns></returns>
		/// <created author="laurentiu.macovei" date="Wed, 29 Nov 2006 11:19:31 GMT"/>
		public StringBuilder Replace(string oldValue, string newValue)
		{
			return sb.Replace(oldValue, newValue);
		}

		/// <summary>
		/// </summary>
		/// <param name="oldChar"></param>
		/// <param name="newChar"></param>
		/// <param name="startIndex"></param>
		/// <param name="count"></param>
		/// <returns></returns>
		/// <created author="laurentiu.macovei" date="Wed, 29 Nov 2006 11:19:31 GMT"/>
		public StringBuilder Replace(char oldChar, char newChar, int startIndex, int count)
		{
			return sb.Replace(oldChar, newChar, startIndex, count);
		}


		#endregion Business Methods


		#region Business Methods


		///// <summary>
		///// </summary>
		///// <param name="value"></param>
		///// <returns></returns>
		//public StringBuilder Append(ushort value)
		//{
		//    return sb.Append(value);
		//}

		///// <summary>
		///// </summary>
		///// <param name="value"></param>
		///// <returns></returns>
		//public StringBuilder Append(uint value)
		//{
		//    return sb.Append(value);
		//}
		#endregion Business Methods

	}
}
